package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Company;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/4/4
 * <p>
 * 选择公司
 */

public class CompanySelectAdapter extends RecyclerAdapter<Company, CompanySelectAdapter.CompanySelectViewHolder> {

    public CompanySelectAdapter(Context context, List<Company> dataList) {
        super(context, dataList);
    }

    @Override
    public CompanySelectViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_company_select, null);
        return new CompanySelectViewHolder(view);
    }

    @Override
    public void onBindViewHolder(CompanySelectViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class CompanySelectViewHolder extends RecyclerAdapter.BaseViewHolder<Company> {
        @BindView(R.id.company_name)
        HXTextView companyName;

        public CompanySelectViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(int position) {
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            itemView.setLayoutParams(params);
            final Company company = dataList.get(position);
            companyName.setText(company.getName());
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickListener.onClick(company);
                }
            });
        }
    }
}
